#include "library.h"

// 用户注册
void Regist() {
 
     char username[32],password[32],sex[4];
    while (1)
    {
        memset(username,0,sizeof(username));
        memset(password,0,sizeof(password));
        memset(sex,0,sizeof(sex));
        printf("请输入用户名：");
        scanf("%s",username);
        printf("请设置密码（6-18位，由数字与字母组成）：");
        scanf("%s",password);
        printf("请输入性别(M-男,W-女)：");
        fflush(stdin);
        scanf("%s",sex);
        if(strcmp(sex,"M")!=0 && strcmp(sex,"W")!=0)
        {
            printf("请输入正确的性别！\n");
            continue;
        }
        int res = CheckRepeat(username);
        if(res==1)
        {
            printf("用户名已被占用！请重新输入!\n");
            continue;
        }
        else if(res==-1)
        {
            printf("注册失败!\n");
            continue;
        }
        int len = strlen(password);
        if(len<6 || len>18)
        {
            printf("密码为6-18位！请重新设置！\n");
            continue;
        }
        //入表
        res=InsertUserTable(username,password,sex);
        if(res==-1)
        {
            printf("注册失败!\n");

        }
        else    printf("注册成功！您的ID为:%d\n",res);
        break;
}
}

// 用户登录
void Login() {
  
    char username[32], password[32];
    int attempts = 0;
    const int max_attempts = 3; 
    int require_captcha = 0;
    
    
    
    printf("\n==== 用户登录 ====\n");
    
    while (attempts < max_attempts) {
        memset(username, 0, sizeof(username));
        memset(password, 0, sizeof(password));
        
        // 检查是否需要验证码（失败三次后）
        if (attempts >= 3 && !require_captcha) {
            send_mock_verify_code(username);
            require_captcha = 1;
        }
        
        if (require_captcha) {
            int input_code;
            printf("请输入验证码: ");
            scanf("%d", &input_code);
            if (!verify_verify_code(input_code)) {
                attempts++;
                printf("账号或密码错误！剩余尝试次数: %d\n", max_attempts - attempts);
                continue;
            }
            // 验证码正确后继续验证账号密码
        }
        
        printf("用户名: ");
        scanf("%s", username);
        printf("密码: ");
        scanf("%s", password);
        
        sqlite3_stmt *stmt;
        const char *sql = "SELECT id, password ,power FROM user WHERE username = ? AND power < 1;";
        
        int res = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
        if (res != SQLITE_OK) {
            printf("数据库错误！\n");
            sqlite3_finalize(stmt);
            continue;
        }
        
        sqlite3_bind_text(stmt, 1, username, -1, SQLITE_STATIC);
        
        if (sqlite3_step(stmt) == SQLITE_ROW) {
            const char *db_password = (const char *)sqlite3_column_text(stmt, 1);
            int power =sqlite3_column_int(stmt, 2);
            if (strcmp(password, db_password) == 0) {
                if (power == USER_BLACKLIST) {
                printf("该用户已被加入黑名单，无法登录！\n");
    
                sqlite3_finalize(stmt);
    
                return;

            }
        
                int user_id = sqlite3_column_int(stmt, 0);
                printf("\n登录成功！\n");
                sqlite3_finalize(stmt);
                
                UserMenu(username);
                return;
            }
        }
        
        sqlite3_finalize(stmt);
        attempts++;
        printf("账号或密码错误！剩余尝试次数: %d\n", max_attempts - attempts);
        int cho=1;
        printf("是否返回主菜单（1继续登录，2返回主菜单）:");
        scanf("%d",&cho);
        if(cho==1) continue;
        else if(cho==2) return;
        else {printf("无效输入，返回主菜单\n");return;}
    }
    
    printf("登录失败次数过多，返回主菜单。\n");
        
}
//         printf("用户名或密码错误！\n");
//         sqlite3_finalize(stmt);
        
//         printf("(1)重新登录 (2)返回主菜单\n");
//         int choice;
//         scanf("%d", &choice);
//         if (choice == 2) {
//             return ;
//         }

// }

// 列出所有用户 (管理员功能)
void listAllUser() {
    if (currentUser == NULL || currentUser->power != USER_ROOT) {
        printf("权限不足!\n");
        return;
    }

    printf("\n--- 所有用户列表 ---\n");
    sqlite3_stmt *stmt;
    const char *sql = "SELECT id, username, power FROM user";
    int rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
    if (rc != SQLITE_OK) {
        fprintf(stderr, "SQL错误: %s\n", sqlite3_errmsg(db));
        return;
    }

    while (sqlite3_step(stmt) == SQLITE_ROW) {
        User user;
        user.id = sqlite3_column_int(stmt, 0);
        strcpy(user.username, (const char*)sqlite3_column_text(stmt, 1));
        user.power = (UserPower)sqlite3_column_int(stmt, 2);
        printUserDetails(&user);
    }
    sqlite3_finalize(stmt);
}

// 修改用户权限 (管理员功能)
void changeUserPower() {
    if (currentUser == NULL || currentUser->power != USER_ROOT) {
        printf("权限不足!\n");
        return;
    }

    int userId;
    printf("\n--- 修改用户权限 ---\n");
    printf("请输入要修改的用户ID: ");
    scanf("%d", &userId);
    clearInputBuffer();

    // 获取当前用户信息
    sqlite3_stmt *stmt;
    const char *sql = "SELECT username, power FROM user WHERE id = ?";
    int rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
    if (rc != SQLITE_OK) {
        fprintf(stderr, "SQL错误: %s\n", sqlite3_errmsg(db));
        return;
    }

    sqlite3_bind_int(stmt, 1, userId);
    rc = sqlite3_step(stmt);
    if (rc != SQLITE_ROW) {
        printf("未找到ID为%d的用户!\n", userId);
        sqlite3_finalize(stmt);
        return;
    }

    User user;
    user.id = userId;
    strcpy(user.username, (const char*)sqlite3_column_text(stmt, 0));
    user.power = (UserPower)sqlite3_column_int(stmt, 1);
    sqlite3_finalize(stmt);

    printf("当前用户信息:\n");
    printUserDetails(&user);
    printf("\n新的权限 (0-普通用户, 1-管理员): ");
    int power;
    scanf("%d", &power);
    clearInputBuffer();

    if (power != 0 && power != 1) {
        printf("无效的权限值!\n");
        return;
    }

    // 更新用户权限
    sql = "UPDATE user SET power = ? WHERE id = ?";
    rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
    if (rc != SQLITE_OK) {
        fprintf(stderr, "SQL错误: %s\n", sqlite3_errmsg(db));
        return;
    }

    sqlite3_bind_int(stmt, 1, power);
    sqlite3_bind_int(stmt, 2, userId);
    rc = sqlite3_step(stmt);
    if (rc != SQLITE_DONE) {
        fprintf(stderr, "更新失败: %s\n", sqlite3_errmsg(db));
    } else {
        printf("用户权限修改成功!\n");
    }
    sqlite3_finalize(stmt);
}

// 查看个人信息
void viewUserInfo() {
    if (currentUser == NULL) {
        printf("请先登录!\n");
        return;
    }

    printf("\n--- 个人信息 ---\n");
    printUserDetails(currentUser);

    // 显示当前借阅的图书
    printf("\n当前借阅的图书:\n");
    sqlite3_stmt *stmt;
    const char *sql = "SELECT id, bookname, author, publisher, category, years, returnDate "
                     "FROM book WHERE borrowerId = ? AND status = ?";
    int rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
    if (rc != SQLITE_OK) {
        fprintf(stderr, "SQL错误: %s\n", sqlite3_errmsg(db));
        return;
    }

    sqlite3_bind_int(stmt, 1, currentUser->id);
    sqlite3_bind_int(stmt, 2, BOOK_BORROWED);
    int count = 0;

    while (sqlite3_step(stmt) == SQLITE_ROW) {
        Book book;
        book.id = sqlite3_column_int(stmt, 0);
        strcpy(book.bookname, (const char*)sqlite3_column_text(stmt, 1));
        strcpy(book.author, (const char*)sqlite3_column_text(stmt, 2));
        strcpy(book.publisher, (const char*)sqlite3_column_text(stmt, 3));
        strcpy(book.category, (const char*)sqlite3_column_text(stmt, 4));
        book.years = sqlite3_column_int(stmt, 5);
        book.status = BOOK_BORROWED;
        book.borrowerId = currentUser->id;
        book.returnDate = sqlite3_column_int64(stmt, 6);
        printBookDetails(&book);
        count++;
    }
    sqlite3_finalize(stmt);

    if (count == 0) {
        printf("没有正在借阅的图书\n");
    }
}

// 注销
void logout() {
    if (currentUser != NULL) {
        free(currentUser);
        currentUser = NULL;
    }
    printf("注销成功!\n");
}

// 打印用户详情
void printUserDetails(User* user) {
    printf("ID: %d\n", user->id);
    printf("用户名: %s\n", user->username);
    printf("权限: %s\n", user->power == USER_ROOT ? "管理员" : "普通用户");
}




int CheckRepeat(const char*username)
{
    sqlite3_stmt *stmt;
    int res=sqlite3_prepare_v2(db,"select * from user;",-1,&stmt,NULL);
    if(res!=SQLITE_OK)
    {
        sqlite3_finalize(stmt);
        return -1;
    }
    while(sqlite3_step(stmt)==SQLITE_ROW)
    {
        if(strcmp(sqlite3_column_text(stmt,1),username)==0)
        {
            sqlite3_finalize(stmt);
            return 1;
        }
    }
    sqlite3_finalize(stmt);
    return 0;
}





// 管理员登录
void AdminLogin() {
    // printf("====管理员登录====\n");
    // Login(); // 实际登录逻辑与普通用户相同，权限在登录后检查
     char username[32], password[32];
    int attempts = 0;
    const int max_attempts = 3;  
    int require_captcha = 0;
    
    printf("\n==== 管理员登录 ====\n");
    
    while (attempts < max_attempts) {
        memset(username, 0, sizeof(username));
        memset(password, 0, sizeof(password));
        
        // 检查是否需要验证码（失败三次后）
        if (attempts >= 3 && !require_captcha) {
            send_mock_verify_code(username);
            require_captcha = 1;
        }
        
        if (require_captcha) {
            int input_code;
            printf("请输入验证码: ");
            scanf("%d", &input_code);
            if (!verify_verify_code(input_code)) {
                attempts++;
                printf("账号或密码错误！剩余尝试次数: %d\n", max_attempts - attempts);
                continue;
            }
            // 验证码正确后继续验证账号密码
        }
        
        printf("管理员账号: ");
        scanf("%s", username);
        printf("密码: ");
        scanf("%s", password);
        
        sqlite3_stmt *stmt;
        const char *sql = "SELECT id, password FROM user WHERE username = ? AND power = 1;";
        
        int res = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
        if (res != SQLITE_OK) {
            printf("数据库错误！\n");
            sqlite3_finalize(stmt);
            continue;
        }
        
        sqlite3_bind_text(stmt, 1, username, -1, SQLITE_STATIC);
        
        if (sqlite3_step(stmt) == SQLITE_ROW) {
            const char *db_password = (const char *)sqlite3_column_text(stmt, 1);
            if (strcmp(password, db_password) == 0) {
                int admin_id = sqlite3_column_int(stmt, 0);
                printf("\n登录成功！\n");
                sqlite3_finalize(stmt);
                
                // 检查是否为默认密码，如果是则要求修改
                if (strcmp(username, "root") == 0 && strcmp(password, "root123456") == 0) {
                    ChangePassword(username, 1); // 1表示管理员强制修改密码
                }
                
                AdminMenu(username);
                return;
            }
        }
        
        sqlite3_finalize(stmt);
        attempts++;
        printf("账号或密码错误！剩余尝试次数: %d\n", max_attempts - attempts);
         int cho=1;
        printf("是否返回主菜单（1继续登录，2返回主菜单）:");
        scanf("%d",&cho);
        if(cho==1) continue;
        else if(cho==2) return;
        else {printf("无效输入，返回主菜单\n");return;}
    }
    
    printf("登录失败次数过多，返回主菜单。\n");
}



// 修改密码
void ChangePassword(const char *username, int is_forced) {
    char current_password[32], new_password[32], confirm_password[32];
    
    if (is_forced) {
        printf("\n首次登录或使用默认密码，必须修改密码！\n");
    } else {
        printf("\n==== 修改密码 ====\n");
    }
    
    while (1) {
        memset(current_password, 0, sizeof(current_password));
        memset(new_password, 0, sizeof(new_password));
        memset(confirm_password, 0, sizeof(confirm_password));
        
        if (!is_forced) {
            printf("当前密码: ");
            scanf("%s", current_password);
        }
        
        printf("新密码: ");
        scanf("%s", new_password);
        printf("确认新密码: ");
        scanf("%s", confirm_password);
        
        // 验证新密码
        if (strcmp(new_password, confirm_password) != 0) {
            printf("两次输入的新密码不一致！\n");
            continue;
        }
        
        // 验证密码复杂度
        if (strlen(new_password) < 6 || strlen(new_password) > 18) {
            printf("密码长度必须为6-18位！\n");
            continue;
        }
        
        // 验证当前密码（如果不是强制修改）
        if (!is_forced) {
            sqlite3_stmt *stmt;
            const char *sql = "SELECT password FROM user WHERE username = ?;";
            
            int res = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
            if (res != SQLITE_OK) {
                printf("数据库错误！\n");
                sqlite3_finalize(stmt);
                continue;
            }
            
            sqlite3_bind_text(stmt, 1, username,-1,SQLITE_TRANSIENT);
            
            if (sqlite3_step(stmt) == SQLITE_ROW) {
                const char *db_password = (const char *)sqlite3_column_text(stmt, 0);
                if (strcmp(current_password, db_password) != 0) {
                    printf("当前密码不正确！\n");
                    sqlite3_finalize(stmt);
                    continue;
                }
            }
            sqlite3_finalize(stmt);
        }
        
        // 更新密码
        char sql[256];
        printf("%s,%s\n", new_password, username);
        snprintf(sql, sizeof(sql), "UPDATE user SET password = '%s' WHERE username = '%s';", new_password, username);
        
        int res = sqlite3_exec(db, sql, NULL, 0, NULL);
        if (res != SQLITE_OK) {
            printf("密码修改失败！\n");
            continue;
        }
        
        printf("密码修改成功！\n");
        break;
    }
}




//调出用户信息
void PersonalInfo(const char * username)
{
    char sql[LEN];
    snprintf(sql,sizeof(sql),"select * from user where username = '%s';",username);
    sqlite3_stmt * stmt;
    int res=sqlite3_prepare_v2(db,sql,-1,&stmt,NULL);
    if(res!=SQLITE_OK)
    {
        sqlite3_finalize(stmt);
        printf("查询错误!\n");
        return ;
    }
    printf("id        username            password            sex     power\n");
    if(sqlite3_step(stmt)==SQLITE_ROW)
    {
        printf("%-10d%-20s%-20s%-8s%s\n",
        sqlite3_column_int(stmt,0),
        sqlite3_column_text(stmt,1),
        sqlite3_column_text(stmt,2),
        sqlite3_column_text(stmt,3),
        sqlite3_column_int(stmt,4)==-1?"黑名单":"普通用户");
    }
    sqlite3_finalize(stmt);

}



//如果找到了，返回1，没找到返回0
int CheckUserInfo(const char*username,const char*password)
{
    char sql[LEN];
    int result = 0;
    char *error = NULL;
    const char *check_user_info = "select * from user where username='%s' and password='%s';";
    snprintf(sql,sizeof(sql),check_user_info,username,password);
    sqlite3_exec(db,sql,CheckCallBack,&result,&error);
    /*
    the 4th argument'&result' will be give to the Callback function's 1st argument
    in this Callback function ,if checked have,the argument result will turn 1,mean check success.
    */
    return result;
}



void ViewAllUsers() {
    printf("\n==== 所有用户信息 ====\n");
    
    sqlite3_stmt *stmt;
    const char *sql = "SELECT id, username, sex FROM user WHERE power = 0 ORDER BY id;";
    
    int res = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
    if (res != SQLITE_OK) {
        printf("数据库错误！\n");
        sqlite3_finalize(stmt);
        return;
    }
    
    printf("%-10s %-20s %-10s\n", "学号", "用户名", "性别");
    printf("----------------------------------------\n");
    
    while (sqlite3_step(stmt) == SQLITE_ROW) {
        printf("%-10d %-20s %-10s\n", 
               sqlite3_column_int(stmt, 0),
               sqlite3_column_text(stmt, 1),
               strcmp(sqlite3_column_text(stmt, 2), "M") == 0 ? "男" : "女");
    }
    
    sqlite3_finalize(stmt);
}


void ViewUserDetails(const char*username) {
    sqlite3_stmt *stmt;
    const char *sql = "SELECT id, username, sex FROM user WHERE username = ? AND power = 0;";
    
    int res = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
    if (res != SQLITE_OK) {
        printf("数据库错误！\n");
        sqlite3_finalize(stmt);
        return;
    }
    
    sqlite3_bind_text(stmt, 1, username,-1,SQLITE_TRANSIENT);
    
    if (sqlite3_step(stmt) == SQLITE_ROW) {
        printf("\n==== 用户详细信息 ====\n");
        printf("id: %d\n", sqlite3_column_int(stmt, 0));
        printf("用户名: %s\n", sqlite3_column_text(stmt, 1));
        printf("性别: %s\n", strcmp(sqlite3_column_text(stmt, 2), "M") == 0 ? "男" : "女");
    } else {
        printf("未找到该用户信息！\n");
    }
    
    sqlite3_finalize(stmt);
}



void ModifyUserInfo() {
    int user_id;
    char new_username[32], new_sex[4];
    char username[32];

     memset(username, 0, sizeof(username));

    ViewAllUsers();
    
    printf("\n请输入要修改的用户的用户名: ");
    scanf("%s", username);
    clearInputBuffer();
    
    // 先显示当前信息
    ViewUserDetails(username);
    
    printf("\n请输入新的用户名: ");
    scanf("%s", new_username);
    clearInputBuffer();
    printf("请输入新的性别(M-男/W-女): ");
    scanf("%s", new_sex);
    
    if (strcmp(new_sex, "M") != 0 && strcmp(new_sex, "W") != 0) {
        printf("性别输入错误！\n");
        return;
    }
    
    char sql[LEN];
    snprintf(sql, sizeof(sql), "UPDATE user SET username = '%s', sex = '%s' WHERE username = '%s';", 
             new_username, new_sex, username);
    
    int res = sqlite3_exec(db, sql, NULL, 0, NULL);
    if (res != SQLITE_OK) {
        printf("修改失败！错误: %s\n", sqlite3_errmsg(db));
    } else {
        printf("用户信息修改成功！\n");
        ViewUserDetails(username); // 显示修改后的信息
    }
}



void ResetUserPassword() {
    int user_id;
    char new_password[32];
    char username[32];

     memset(username, 0, sizeof(username));
    
    ViewAllUsers();
    
    printf("\n请输入要重置密码的用户的用户名: ");
    scanf("%s", username);
    clearInputBuffer();

    printf("请输入新密码: ");
    scanf("%s", new_password);
    clearInputBuffer();

    // 验证密码长度
    if (strlen(new_password) < 6 || strlen(new_password) > 18) {
        printf("密码长度必须为6-18位！\n");
        return;
    }
    char sql[LEN];
    snprintf(sql, sizeof(sql), "UPDATE user SET password = '%s' WHERE username = '%s';", new_password, username);
    
    int res = sqlite3_exec(db, sql, NULL, 0, NULL);
    if (res != SQLITE_OK) {
        printf("密码重置失败！错误: %s\n", sqlite3_errmsg(db));
    } else {
        printf("用户密码重置成功！\n");
    }
}



// 删除学生信息
void DeleteUser() {
    int user_id;
    char username[32];

    memset(username, 0, sizeof(username));
    
    ViewAllUsers();
    
    printf("\n请输入要删除的用户的用户名: ");
    scanf("%s", username);
    
    // 先确认用户存在
    sqlite3_stmt *stmt;
    const char *check_sql = "SELECT username FROM user WHERE username = ? AND power = 0;";
    
    int res = sqlite3_prepare_v2(db, check_sql, -1, &stmt, NULL);
    if (res != SQLITE_OK) {
        printf("数据库错误！\n");
        sqlite3_finalize(stmt);
        return;
    }
    
    sqlite3_bind_text(stmt, 1, username,-1,SQLITE_TRANSIENT);
    
    if (sqlite3_step(stmt) != SQLITE_ROW) {
        printf("未找到该用户信息！\n");
        sqlite3_finalize(stmt);
        return;
    }
    sqlite3_finalize(stmt);
    
    // 确认删除
    printf("确认删除用户名为 %s 的用户信息吗？(y/n): ", username);
    char confirm;
    scanf(" %c", &confirm);
    
    if (confirm != 'y' && confirm != 'Y') {
        printf("已取消删除操作。\n");
        return;
    }
    
    char sql[LEN];
    snprintf(sql, sizeof(sql), "DELETE FROM user WHERE username = '%s';", username);
    
    res = sqlite3_exec(db, sql, NULL, 0, NULL);
    if (res != SQLITE_OK) {
        printf("删除失败！错误: %s\n", sqlite3_errmsg(db));
    } else {
        printf("用户信息删除成功！\n");
    }
}


void BlacklistManagementMenu() {
    while (1) {
        printf("\n==== 黑名单管理 ====\n");
        printf("1. 加入黑名单\n");
        printf("2. 移出黑名单\n");
        printf("3. 查看黑名单用户\n");
        printf("4. 返回上级菜单\n");
        printf("请选择: ");
        
        int choice;
        scanf("%d", &choice);
        clearInputBuffer();
        
        switch (choice) {
            case 1: {
                char username[32];
                printf("请输入要加入黑名单的用户名: ");
                scanf("%s", username);
                addToBlacklist(username);
                break;
            }
            case 2: {
                char username[32];
                printf("请输入要移出黑名单的用户名: ");
                scanf("%s", username);
                removeFromBlacklist(username);
                break;
            }
            case 3:
                listBlacklistedUsers();
                break;
            case 4:
                return;
            default:
                printf("无效选择，请重新输入！\n");
                break;
        }
    }
}


void addToBlacklist(const char* username) {
    char sql[256];
    sprintf(sql, "UPDATE user SET power = %d WHERE username = '%s'", USER_BLACKLIST, username);
    
    char *errMsg = NULL;
    if (sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK) {
        printf("加入黑名单失败: %s\n", errMsg);
        sqlite3_free(errMsg);
    } else {
        if (sqlite3_changes(db) > 0) {
            printf("用户 %s 已加入黑名单!\n", username);
        } else {
            printf("未找到用户 %s\n", username);
        }
    }
}

// 新增功能：移出黑名单
void removeFromBlacklist(const char* username) {
    char sql[256];
    sprintf(sql, "UPDATE user SET power = %d WHERE username = '%s'", USER_NORMAL, username);
    
    char *errMsg = NULL;
    if (sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK) {
        printf("移出黑名单失败: %s\n", errMsg);
        sqlite3_free(errMsg);
    } else {
        if (sqlite3_changes(db) > 0) {
            printf("用户 %s 已移出黑名单!\n", username);
        } else {
            printf("未找到用户 %s 或用户不在黑名单中\n", username);
        }
    }
}

// 新增功能：查看黑名单用户
void listBlacklistedUsers() {
    sqlite3_stmt *stmt;
    const char *sql = "SELECT id, username FROM user WHERE power = ?";
    
    if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
        printf("数据库错误: %s\n", sqlite3_errmsg(db));
        return;
    }
    
    sqlite3_bind_int(stmt, 1, USER_BLACKLIST);
    
    printf("\n=== 黑名单用户 ===\n");
    printf("ID\t用户名\n");
    printf("------------------\n");
    
    int found = 0;
    while (sqlite3_step(stmt) == SQLITE_ROW) {
        printf("%d\t%s\n",
              sqlite3_column_int(stmt, 0),
              sqlite3_column_text(stmt, 1));
        found++;
    }
    
    if (found == 0) {
        printf("黑名单为空\n");
    }
    
    sqlite3_finalize(stmt);
}